package geez.showcase.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.*;
import geez.widget.*;

public class Showcase implements EntryPoint {

    public void onModuleLoad() {
        MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
        oracle.add("Dave");
        oracle.add("Derek");
        oracle.add("Dilbert");
        oracle.add("Daffid");
        oracle.add("Del boy");
        oracle.add("Bob");
        oracle.add("Martha");
        oracle.add("George");
        oracle.add("Greg");
        oracle.add("Frankie");

        GSuggestBox suggestBox = new GSuggestBox(oracle)
                .popupCss("popups")
                .withRenderer(evenOddRenderer());

        final GPopupPanel popupPanel = new GPopupPanel(new GLabel("Pop Up Contents"), true);
        GButton popupButton = new GButton("Show pop up")
                .add(new ClickListener() {
                    public void onClick(Widget widget) {
                        popupPanel.show();
                        popupPanel.positionBelowAlignRight(widget);
                    }
                });
        GFlowPanel showcasePanel = new GFlowPanel()
                .append(suggestBox)
                .append(popupButton);

        RootPanel.get("showcase").add(showcasePanel);
    }

    private GSuggestionRenderer evenOddRenderer() {
        return new GSuggestionRenderer() {
            public Widget render(SuggestOracle.Suggestion suggestion, int index) {
                return new GLabel(suggestion.getReplacementString())
                        .css((index % 2 == 0) ? "even" : "odd");
            }
        };
    }
}
